package com.example.demo.controller;

import com.example.demo.result.JsonResult;
import com.example.demo.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author zhanpengguo
 * @date 2019-07-04 14:08
 */
@Controller
public class LoginController {

    @Autowired
    LoginService loginService;

    @PostMapping("/login")
    @ResponseBody
    public JsonResult login(@RequestParam("username") String username, @RequestParam("password") String password){
        try {
            return loginService.jwtLogin(username, password);
        }catch (Exception e){
            return new JsonResult(new Throwable(e));
        }
    }
}
